<%inherit file="base.html"/>

<%def name="head()">
<link href="/static/js/toastr.min.css" rel="stylesheet" type="text/css"/>
<script src="/static/js/toastr.min.js"></script>
<script>
function restart(name){
    $.get("/admin/superrpc/restart", {name:name}, function (ev) {
        ev.code==0 ? toastr.info(ev.msg) : toastr.error(ev.msg);
        setTimeout("window.location.reload()",1500);
    }, "json");
}
function stop(name){
    $.get("/admin/superrpc/stop", {name:name}, function (ev) {
        ev.code==0 ? toastr.info(ev.msg) : toastr.error(ev.msg);
        setTimeout("window.location.reload()",1500);
    }, "json");
}

var bar_opts =  {
  "closeButton": true,
  "debug": false,
  "newestOnTop": false,
  "progressBar": true,
  "positionClass": "toast-top-right",
  "preventDuplicates": false,
  "onclick": null,
  "showDuration": "300",
  "hideDuration": "500",
  "timeOut": "15000",
  "extendedTimeOut": "15000",
  "showEasing": "swing",
  "hideEasing": "linear",
  "showMethod": "fadeIn",
  "hideMethod": "fadeOut"
}

function restartall(){
    if (!confirm("确认此操作吗？")) {
        return false;
    }  
    $.get("/admin/superrpc/restartall", {}, function (ev) {
        toastr.info(ev.msg,'',bar_opts);
        setTimeout("window.location.reload()",10000);
    }, "json");
}
function reloadconfig(){
    $.get("/admin/superrpc/reloadconfig", {}, function (ev) {
        toastr.info(ev.msg,'',bar_opts);
        setTimeout("window.location.reload()",10000);
    }, "json");
}
var clogfile;
function taillog(logfile){
    clogfile = logfile;
    $.get("/admin/superrpc/taillog", {logfile:logfile}, function (ev) {
        $("#loginfo").html(ev.log)
        $('#logbox').modal({})
    }, "json");
}
</script>
</%def>

<%def name="body()">
<section class="content">
    <div class="box box-default">
        <div class="box-header">
            <i class="fa fa-users"></i>
            <h3 class="box-title">系统状态管理</h3>
            <div class="bar pull-right">
             <a href="javascript:window.location.reload();"><i class="fa fa-refresh"></i> 刷新</a>
            </div>              
        </div>
        <div class="box-body">
            <div class="container">
                % if current_user.opr_type == 0:
                <div class="pull-left bottom10">
                     <a href="javascript:reloadconfig();" class="btn btn-sm bg-navy"><i class="fa fa-refresh"></i>  重载系统配置</a>
                     <a href="javascript:restartall();" class="btn btn-sm bg-navy"><i class="fa fa-play-circle"></i>  重启所有服务</a>
                </div>
                % endif            
                <table class="table">
                    <thead>
                        <tr>
                            <th>状态</th>
                            <th>名称</th>
                            <th>描述</th>
                             % if current_user.opr_type == 0:
                            <th>操作</th>
                             % endif
                        </tr>
                    </thead>
                    <tbody>
                        % for proc in procs:
                            <tr>
                                <td>${handler.state_desc(proc.get('state',0))}</td>
                                <td>${handler.name_desc(proc.get('name'))}</td>
                                <td>${proc.get('description')}</td>
                                 % if current_user.opr_type == 0:
                                <td>
                                % if current_user.opr_type == 0:
                                    % if proc.get('name') != 'manage':
                                    <a class="opt-btn btn-default" href="javascript:restart('${proc["name"]}')">
                                    <i class="fa fa-play"></i> 重启</a>
                                    <a class="opt-btn btn-default" href="javascript:stop('${proc["name"]}')">
                                    <i class="fa fa-pause"></i> 停止</a>
                                    % endif
                                <a class="opt-btn btn-default" href="javascript:taillog('${proc["stdout_logfile"]}')">
                                <i class="fa fa-hdd-o"></i> 日志</a>
                                <a class="opt-btn btn-default" href="/admin/superrpc/logdownload?logfile=${proc['stdout_logfile']}">
                                <i class="fa fa-hdd-o"></i> 日志下载</a>
                                % endif
                                </td>
                                % endif
                            </tr>
                        % endfor
                    </tbody>
                </table>
            </div>
        </div>
    </div>


<!-- Modal -->
<div class="modal fade" id="logbox" tabindex="-1" role="dialog" aria-labelledby="logModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="logModalLabel">服务日志</h4>
      </div>
      <div class="modal-body">
        <div id="loginfo" class="msg-box break-all" style="height:420px;overflow:auto;background-color:black;color:#09E100;"></div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" onclick="taillog(clogfile);">刷新</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


</section>
</%def>